package com.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.sfzy.entity.ConsultantLevel;
import com.sfzy.service.ConsultantLevelService;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("consultantLevel")
public class ConsultantLevelController {
    @Autowired
    private ConsultantLevelService consultantLevelService;
    //增加
    @PostMapping("add")
    public R insertConsultantLevel(@RequestBody ConsultantLevel consultantLevel) {
        int num = consultantLevelService.insertConsultantLevel(consultantLevel);
        if (num > 0) {
            return R.ok();
        }else{
            return R.fail();
        }
    }
    //删除
    @DeleteMapping("{id}")
    public R deleteConsultantLevel(@PathVariable("id") int id) {
        int num = consultantLevelService.deleteConsultantLevel(id);
        if (num > 0) {
            return R.ok();
        }else{
            return R.fail();
        }
    }
    //修改
    @PutMapping("update")
    public R updateConsultantLevel(@RequestBody ConsultantLevel consultantLevel) {
        int num = consultantLevelService.updateConsultantLevel(consultantLevel);
        if (num > 0) {
            return R.ok();
        }else{
            return R.fail();
        }
    }
    //根据id查询
    @GetMapping("{id}")
    public R getConsultantLevelById(@PathVariable("id") int id) {
        ConsultantLevel consultantLevel = consultantLevelService.selectConsultantLevel(id);
        return R.ok(consultantLevel);
    }
    //分页查询
    @GetMapping("page")
    public R getConsultantLevels(ConsultantLevel consultantLevel,
                                 @RequestParam(required = false,defaultValue = "1")int pageNum,
                                 @RequestParam(required = false,defaultValue = "3")int pageSize) {
        PageInfo<ConsultantLevel> consultantLevelPageInfo = consultantLevelService.selectAllConsultantLevel(consultantLevel, pageNum, pageSize);
        return R.ok(consultantLevelPageInfo);
    }
}
